﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Nomad.WebSync.Windows.Forms {
    /// <summary>
    /// Interaction logic for Settings.xaml
    /// </summary>
    public partial class Settings : Page {
        public Settings() {
            InitializeComponent();
        }

        private void getCurrentSettings() {
            serviceTextBox.Text = Services.Desktop.url;
        }

        private void saveNewSettings() {
            Properties.Settings.Default.Service = serviceTextBox.Text;
            Properties.Settings.Default.Save();
            Properties.Settings.Default.Upgrade();
        }

        private void saveButton_Click(object sender, RoutedEventArgs e) {
            this.Cursor = Cursors.Wait;
            try {
                this.saveNewSettings();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            } finally {
                this.Cursor = Cursors.Arrow;
            }
        }
        private void cancelButton_Click(object sender, RoutedEventArgs e) {
            this.Cursor = Cursors.Wait;
            try {
                NavigationService.GoBack();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            } finally {
                this.Cursor = Cursors.Arrow;
            }
        }
        private void Page_Loaded(object sender, RoutedEventArgs e) {
            this.Cursor = Cursors.Wait;
            try {
                this.getCurrentSettings();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            } finally {
                this.Cursor = Cursors.Arrow;
            }
        }
    }
}
